<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 商家联合促销商家
 */
namespace app\allwin\model;
use think\Model;

class AllwinUnmarketStore extends Model{

    protected $pk = 'id';
    
    //是否核销
    public function verif(){
        return $this->hasOne('AllwinUnmarketVerif','store_id','id');
    }

    //添加或编辑
    public static function edit(array $param){
        $data = [
            'union_id' => $param['union_id'],
            'name'     => trim($param['name']),
            'address'  => trim($param['address']),
            'telphone' => trim($param['tel']),
            'content'  => $param['content'],
            'note'     => $param['note'],
            'about'    => $param['about'],
            'pictext'  => $param['pictext'],
            'img'      => $param['img'],
            'imgs'     => json_encode($param['imgs']),
            'endtime'  => strtotime($param['end_time']),
            'store_id' => $param['store_id'],
        ];
        if(isset($param['id'])){
            $condition['id']                = $param['id'];
            $condition['member_miniapp_id'] = $param['member_miniapp_id'];
            return self::where($condition)->update($data);
        }else{
            $data['member_miniapp_id'] = $param['member_miniapp_id'];
            return self::insert($data);
        }
    }
}